namespace Healinker.Entities.Migrations
{
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "DiseaseClassifications",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ParentId = c.Int(nullable: false),
                        Name = c.String(),
                        Order = c.Int(nullable: false),
                        CodeScope = c.String(),
                        CodeClassificationId = c.Int(nullable: false),
                        QueryCode = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("CodeClassifications", t => t.CodeClassificationId, cascadeDelete: true)
                .Index(t => t.CodeClassificationId);
            
            CreateTable(
                "CodeClassifications",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "Diseases",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DiseaseClassificationId = c.Int(nullable: false),
                        CodeClassificationId = c.Int(nullable: false),
                        Name = c.String(),
                        ICDCode = c.String(),
                        QueryCode = c.String(),
                        AliasName = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("DiseaseClassifications", t => t.DiseaseClassificationId, cascadeDelete: true)
                .ForeignKey("CodeClassifications", t => t.CodeClassificationId, cascadeDelete: true)
                .Index(t => t.DiseaseClassificationId)
                .Index(t => t.CodeClassificationId);
            
            CreateTable(
                "DiseaseCauses",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DiseaseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Diseases", t => t.DiseaseId, cascadeDelete: true)
                .Index(t => t.DiseaseId);
            
            CreateTable(
                "Treatments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DiseaseId = c.Int(nullable: false),
                        Summary = c.String(),
                        Details = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Diseases", t => t.DiseaseId, cascadeDelete: true)
                .Index(t => t.DiseaseId);
            
            CreateTable(
                "LinkArticles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DiseaseId = c.Int(nullable: false),
                        Author = c.String(),
                        FromSite = c.String(),
                        PublishDate = c.DateTime(nullable: false),
                        Keywords = c.String(),
                        Content = c.String(),
                        Title = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Diseases", t => t.DiseaseId, cascadeDelete: true)
                .Index(t => t.DiseaseId);
            
            CreateTable(
                "Symptoms",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "Medications",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "DiseaseMedications",
                c => new
                    {
                        MedicationId = c.Int(nullable: false),
                        DiseaseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.MedicationId, t.DiseaseId })
                .ForeignKey("Medications", t => t.MedicationId, cascadeDelete: true)
                .ForeignKey("Diseases", t => t.DiseaseId, cascadeDelete: true)
                .Index(t => t.MedicationId)
                .Index(t => t.DiseaseId);
            
            CreateTable(
                "DiseaseComplications",
                c => new
                    {
                        DiseaseId = c.Int(nullable: false),
                        ComplicationDiseaseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.DiseaseId, t.ComplicationDiseaseId })
                .ForeignKey("Diseases", t => t.DiseaseId, cascadeDelete: true)
                .ForeignKey("Diseases", t => t.ComplicationDiseaseId, cascadeDelete: true)
                .Index(t => t.DiseaseId)
                .Index(t => t.ComplicationDiseaseId);
            
            CreateTable(
                "DiseaseSymptoms",
                c => new
                    {
                        SymptomId = c.Int(nullable: false),
                        DiseaseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.SymptomId, t.DiseaseId })
                .ForeignKey("Diseases", t => t.DiseaseId, cascadeDelete: true)
                .ForeignKey("Symptoms", t => t.SymptomId, cascadeDelete: true)
                .Index(t => t.DiseaseId)
                .Index(t => t.SymptomId);
            
        }
        
        public override void Down()
        {
            DropIndex("DiseaseSymptoms", new[] { "SymptomId" });
            DropIndex("DiseaseSymptoms", new[] { "DiseaseId" });
            DropIndex("DiseaseComplications", new[] { "ComplicationDiseaseId" });
            DropIndex("DiseaseComplications", new[] { "DiseaseId" });
            DropIndex("DiseaseMedications", new[] { "DiseaseId" });
            DropIndex("DiseaseMedications", new[] { "MedicationId" });
            DropIndex("LinkArticles", new[] { "DiseaseId" });
            DropIndex("Treatments", new[] { "DiseaseId" });
            DropIndex("DiseaseCauses", new[] { "DiseaseId" });
            DropIndex("Diseases", new[] { "CodeClassificationId" });
            DropIndex("Diseases", new[] { "DiseaseClassificationId" });
            DropIndex("DiseaseClassifications", new[] { "CodeClassificationId" });
            DropForeignKey("DiseaseSymptoms", "SymptomId", "Symptoms");
            DropForeignKey("DiseaseSymptoms", "DiseaseId", "Diseases");
            DropForeignKey("DiseaseComplications", "ComplicationDiseaseId", "Diseases");
            DropForeignKey("DiseaseComplications", "DiseaseId", "Diseases");
            DropForeignKey("DiseaseMedications", "DiseaseId", "Diseases");
            DropForeignKey("DiseaseMedications", "MedicationId", "Medications");
            DropForeignKey("LinkArticles", "DiseaseId", "Diseases");
            DropForeignKey("Treatments", "DiseaseId", "Diseases");
            DropForeignKey("DiseaseCauses", "DiseaseId", "Diseases");
            DropForeignKey("Diseases", "CodeClassificationId", "CodeClassifications");
            DropForeignKey("Diseases", "DiseaseClassificationId", "DiseaseClassifications");
            DropForeignKey("DiseaseClassifications", "CodeClassificationId", "CodeClassifications");
            DropTable("DiseaseSymptoms");
            DropTable("DiseaseComplications");
            DropTable("DiseaseMedications");
            DropTable("Medications");
            DropTable("Symptoms");
            DropTable("LinkArticles");
            DropTable("Treatments");
            DropTable("DiseaseCauses");
            DropTable("Diseases");
            DropTable("CodeClassifications");
            DropTable("DiseaseClassifications");
        }
    }
}
